from fastapi import APIRouter, HTTPException
from .models import OutInputClear, OutInputChange, OutInputSubmit, InInputChange
from .sub_utils import OledControl
import asyncio
import time
import re

router = APIRouter(
    prefix="/OledControl",
    tags=["OLED控制"]
)

dbOled = OledControl()


@router.get("/InputChange", response_model=OutInputChange)
async def inputChange(input: str = InInputChange):
    if input != '':
        dbOled.setInputText(input)
    return {'input': dbOled.getInputText(), 'time': time.time() * 1000}


@router.get("/InputClear", response_model=OutInputClear)
async def inputClear():
    await dbOled.clearInputText()
    return {'status': True, 'time': time.time() * 1000}


@router.get("/InputSubmit", response_model=OutInputSubmit)
async def inputSubmit():
    await dbOled.submitInputText()
    return {'status': True, 'time': time.time() * 1000}